
import { Component, Input, ViewChild } from '@angular/core';
import { DataTableComponent, DialogService, TableWidthConfig } from 'ng-devui';
import { DataSharingService } from 'src/app/@core/services/dataSharing/data-sharing.service';

import { JobOrderService } from 'src/app/@core/services/jobOrder/job-order.service';
import { PurchaseService } from 'src/app/@core/services/purchase/purchase.service';
import { SharedMethodService } from 'src/app/@core/services/Sharedmethod/shared-method.service';
import { environment } from 'src/environments/environment';

@Component({
  selector: 'app-select-tickets',
  templateUrl: './select-tickets.component.html',
  styleUrls: ['./select-tickets.component.scss']
})
export class SelectTicketsComponent {
  @Input() data: any;
  isSelected = false;
  displayTableData: any[] = [];
  tableheight = '230px';
  selectData: any;
  searchName: ''
  pager = {
    total: 20,
    pageIndex: 1,
    pageSize: 20
  }
  pageSizeOptions = [10, 20, 30, 50, 100]
  dataTableOptions = {
    columns: [

      {
        field: '工单号',
        header: '工单号',
        fieldType: 'text',
        fixedLeft: "80px"
      },

      {
        field: '工序序号',
        header: '工序序号',
        fieldType: 'text',
      },
      {
        field: '工序编码',
        header: '工序编码',
        fieldType: 'text',
      },
      {
        field: '工序名称',
        header: '工序名称',
        fieldType: 'text',
      },
      {
        field: '产品编码',
        header: '产品编码',
        fieldType: 'text',
      },
      {
        field: '产品名称',
        header: '产品名称',
        fieldType: 'text',
      },
      {
        field: '产品规格',
        header: '产品规格',
        fieldType: 'text',
      },
      {
        field: '操作工',
        header: '操作工',
        fieldType: 'text',
      },
      {
        field: '状态',
        header: '状态',
        fieldType: 'text',
      },
      {
        field: '计划数',
        header: '计划数',
        fieldType: 'text',
      },

      {
        field: '完成进度',
        header: '完成进度',
        fieldType: 'text',
      },
      {
        field: '剩余数',
        header: '剩余数',
        fieldType: 'text',
      },

      {
        field: '计划开工时间',
        header: '计划开工时间',
        fieldType: 'text',
      },
      {
        field: '计划完工时间',
        header: '计划完工时间',
        fieldType: 'text',
      },
    ]
  }
  tableWidthConfig: TableWidthConfig[] = [
    {
      field: 'checkbox',
      width: '80px',

    },
    {
      field: '工单号',
      width: '140px'
    },
    {
      field: '工序序号',
      width: '160px'
    },

    {
      field: '工序编码',
      width: '150px'
    },
    {
      field: '工序名称',
      width: '100px'
    },
    {
      field: '规格型号',
      width: '100px'
    },
    {
      field: '工序序号',
      width: '100px'
    },
    {
      field: '工序',
      width: '100px'
    },
    {
      field: '操作工',
      width: '100px'
    },
    {
      field: '状态',
      width: '100px'
    },
    {
      field: '计划数',
      width: '100px'
    },
    {
      field: '完成进度',
      width: '150px'
    },
    {
      field: '剩余数',
      width: '100px'
    },

    {
      field: '计划开工时间',
      width: '100px'
    },
    {
      field: '计划完工时间',
      width: '100px'
    },
  ]
  options = [
    '已派工',
    '未派工',
  ]
  weiWaiOptions = [
    '委外',
    '未委外',
  ]
  weiwai: string
  getParts: any = {}
  partNum: string = null;
  partName: string = null;
  JobOrderNum: string = null;
  JobOrderStatus: string = null;
  JobOrderType: string = null;
  StartDate: string = null;
  EndDate: string = null;
  jobOrderProcesses: any[] = [];
  productJob = []
  tableData = [];
  checkRows: any[] = [];
  PartNum: string = null;
  PartName: string = null;
  ProcessNum: string = null;
  ProcessName: string = null;
  isIconRotated = false;
  @ViewChild(DataTableComponent, { static: true }
  ) datatable!: DataTableComponent;//获取table
  constructor(private SharedMethodService: SharedMethodService, private JobOrderService: JobOrderService) { }
  ngOnInit(): void {
    this.search()
  }
  pageIndexChange($event: any) {
    this.pager.pageIndex = $event;
    this.search()
  }//切换页码
  pageSizeChange($event: any) {
    this.search()
  }//改变每页显示数量
  search() {
    this.JobOrderService.GetJobOrdersProcess2(this.PartNum, this.PartName, this.JobOrderNum, this.JobOrderStatus, this.ProcessNum, this.ProcessName, this.pager.pageIndex, this.pager.pageSize, this.weiwai, false).subscribe((data: any) => {
      this.tableData = data.items
      this.pager.total = data.totalCount
    })
  }
  reset() {
    this.JobOrderNum = null,
      this.JobOrderStatus = null,
      this.JobOrderType = null,
      this.StartDate = null,
      this.EndDate = null,
      this.PartNum = null,
      this.PartName = null,
      this.ProcessNum = null,
      this.ProcessName = null,
      this.weiwai = null
    this.search()
  }
  onRowCheckChange(checked: any, rowIndex: any, nestedIndex: any, rowItem: { $checked: any; $halfChecked: boolean; }) {
    this.SharedMethodService.onRowCheckChange(checked, rowIndex, nestedIndex, rowItem, this.datatable)
    this.getParts = {
      pageNumber: 1,
      pageSize: 999,
      jobOrderProcessIds: this.checkRows
    }
  }
  getCheckedRows() {
    this.SharedMethodService.getCheckedRows(this.datatable, 'jobOrderProcessId').subscribe((data: any) => {
      this.checkRows = data;
      this.getParts = {
        pageNumber: 1,
        pageSize: 999,
        jobOrderProcessIds: this.checkRows
      }
    })
  }//获取选中行
  cleared() {
    this.SharedMethodService.cleared(this.checkRows, this.checkRows, this.datatable).subscribe((data: any) => {
      this.checkRows = data;
    })
  }//清空选中行
  getUsers(item: any) {
    return item.map((item: any) => {
      return item.name
    }).join(',')
  }
}
